
* This do file generates Figure A11

/*
Structure of the do file:
1. Open datasets, generate relevant variables, and save auxiliary datasets
2. Merge auxiliary datasets and add information for provinces with no female councilors for that period
3. Add population, and prepare the dataset 
4. Generate the figure 
*/


*** Appointed and Elected Councilors, 1924-1939

** Count total # of women by province

use "Datasets/00_rawdata/women_councilor_names.dta", clear
bysort province: gen tool= _N
bysort province: egen total_women_all = max(tool)
bysort province: gen case = _n
keep if case == 1
drop case

keep province total_women_all

save "Datasets/01_processeddata/women_councillors_all.dta", replace


*** Elected Councilors, 1931-1939

** Count total # of women by province

use "Datasets/00_rawdata/women_councilor_names.dta", clear
drop if period == "1924-1930"
bysort province: gen tool = _N
bysort province: egen total_women_democ = max(tool)
bysort province: gen case = _n
keep if case == 1
drop case

keep province total_women_democ

save "Datasets/01_processeddata/total_women_democ.dta", replace


*** Merge both counts

use "Datasets/01_processeddata/women_councillors_all.dta", clear

merge 1:1 province using "Datasets/01_processeddata/total_women_democ.dta"
drop _merge 


*** Complete provinces (the merge brings in provinces without any councilor)
merge 1:1 province using "Datasets/00_rawdata/provincias"
drop _merge 
replace total_women_all = 0 if total_women_all == .
replace total_women_democ = 0 if total_women_democ == . 
sum total_women* 


*** Add province population in 1930
merge 1:1 province using "Datasets/00_rawdata/pop_1930_ine"
drop _merge

** Keep same sample than main analysis (= drop Canary Island provinces)
drop if province == "Las Palmas"
drop if province == "Tenerife"


*** Other data 

** Indicator Variable for Provinces with Prevalence of Stem Family
gen stem_dum = 0 
replace stem_dum = 1 if province == "Alava"
replace stem_dum = 1 if province == "Barcelona"
replace stem_dum = 1 if province == "Girona"
replace stem_dum = 1 if province == "Guipuzcoa"
replace stem_dum = 1 if province == "Huesca"
replace stem_dum = 1 if province == "Lleida"
replace stem_dum = 1 if province == "Navarra"
replace stem_dum = 1 if province == "Tarragona"
replace stem_dum = 1 if province == "Vizcaya"

label define stem_dum_lab 0 " Nuclear Province" 1 "Stem Province"
label values stem_dum stem_dum_lab
tab stem_dum

** Women councilors per 1 million inhabitants
gen total_regidores_million_cap_all = 1000000*(total_women_all/pop_1930_ine)
gen total_regidores_million_cap_dem = 1000000*(total_women_democ/pop_1930_ine)


***********************
* FIGURES A11
***********************

* Full period
ciplot total_regidores_million_cap_all, by(stem_dum) level(90) ytitle(Women Councilors per million cap) xtitle("")
graph export "Figures/FigureA11a.pdf", replace

* Only democratic period
ciplot total_regidores_million_cap_dem, by(stem_dum) level(90) ytitle(Women Councilors per million cap) xtitle("")
graph export "Figures/FigureA11b.pdf", replace
